package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup

//1.启动一个gorouting,生产100个数字发送到ch1
func f3(ch1 chan int) {
	defer wg.Done()
	for i := 0; i < 10; i++ {
		fmt.Println("i===", i)
		ch1 <- i
	}
	close(ch1)
}
func f4(ch1 chan int, ch2 chan int) {
	defer wg.Done()
	for x := range ch1 {
		fmt.Println("xxx===", x)
		ch2 <- x * x
	}
	close(ch2)
}

func main() {

	a := make(chan int, 2)
	b := make(chan int, 2)
	wg.Add(2)
	go f3(a)
	go f4(a, b)

	//3.在main 中，取出ch2值打印
	for ret := range b {
		fmt.Println("ret===", ret)
	}
	wg.Wait()
}
